<%-- 
    Document   : Home
    Created on : Jul 21, 2013, 7:48:16 PM
    Author     : Ndnam
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="classes.Auction"%>
<%@page import="classes.Auction"%>
<%@page import="classes.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="auctionDAO" class="classes.AuctionDAO"/>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>HamsterBid</title>
    </head>
    <body>
        <form action="Search.jsp">
            <input type="text" name="keyword"><input type="submit" value="Search Product">
        </form>
        <%
            if (request.getParameter("logout") != null) session.invalidate();
            session = request.getSession(true);
            User user = (User) session.getAttribute("user");
            if (user != null) {
                out.println("Welcome <a href=\"UserProfile.jsp\">" + user.getFirstname() + "</a>  <a href=\"Home.jsp?logout=true\">Log out</a><br>"
                        + "<a href=\"CreateAuction.jsp\">Create an auction</a>");
            } else {
                out.println("<a href=\"Login.jsp\">Log in</a>  <a href=\"InsertUser.jsp\">Register</a>");
            }
        %><br>

        Auction List:<br>
        <%ArrayList<Auction> listAuction = auctionDAO.getAuctionTable();%>
        <table border='1'>
            <tr>
                <td>Creator</td>
                <td>Product Type</td>
                <td>Product Name</td>
                <td>Initial Price</td>
                <td>Last bid</td>
                <td>Begin time</td>
                <td>Begin date</td>
                <td>End time</td>
                <td>End date</td>
                <td>State</td>
            </tr>
            <% for (Auction item : listAuction) {
                    out.println("<tr>"
                            + "<td>" + auctionDAO.searchUserByID(item.getCreator()).getUsername() + "</td>"
                            + "<td>" + auctionDAO.searchProductTypeByID(item.getProductType()).getType() + "</td>"
                            + "<td>" + item.getProductName() + "</td>"
                            + "<td>" + item.getInitialPrice() + "</td>"
                            + "<td>" + item.getLastPrice() + "</td>"
                            + "<td>" + item.getBeginTime() + "</td>"
                            + "<td>" + item.getBeginDate() + "</td>"
                            + "<td>" + item.getEndTime() + "</td>"
                            + "<td>" + item.getEndDate() + "</td>"
                            + "<td>" + item.getState() + "</td>"
                            + "<td><a href=\"BidScreen.jsp?auction=" + item.getAuctionID()+ "\">Enter</td>"
                            + "</tr>");
                }
            %>
        </table><br>


    </body>
</html>
